package com.daikit.daikit4gxt.client.action;

import com.google.gwt.user.client.rpc.AsyncCallback;


/**
 * Wrapp a callback inside this DkAsyncCallbackWrapper to
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 * @param <EXPECTED_TYPE>
 * @param <RETRIEVED_TYPE>
 */
public abstract class DkAsyncCallbackWrapper<EXPECTED_TYPE, RETRIEVED_TYPE> implements AsyncCallback<RETRIEVED_TYPE>
{

	private final AsyncCallback<EXPECTED_TYPE> callback;

	/**
	 * Constructor
	 * 
	 * @param callback
	 *           the callback to be wrapped
	 */
	public DkAsyncCallbackWrapper(final AsyncCallback<EXPECTED_TYPE> callback)
	{
		this.callback = callback;
	}

	@Override
	public void onFailure(final Throwable caught)
	{
		callback.onFailure(caught);
	}

	@Override
	public void onSuccess(final RETRIEVED_TYPE result)
	{
		callback.onSuccess(wrapResult(result));
	}

	protected abstract EXPECTED_TYPE wrapResult(RETRIEVED_TYPE result);

}
